package com.v1.video.domain;

import android.content.Context;
import android.content.SharedPreferences;

public class OptionInfo {

	private static OptionInfo instance;
	
	private OptionInfo(){
		
	}
	
	public static OptionInfo getInstance(Context context){
		if(instance == null){
			instance = new OptionInfo();
		}
		if(!loaded){
			instance.loadData(context);
			loaded = true;
		}
		return instance;
	}
	
	/** 是否已经读取 */
	private static boolean loaded = false;
	
	/** 详情页自动播放 */
	private boolean videoDetailPageAutoPlay = true;
	/** 任何网络下自动播放 */
	private boolean videoAutoPlayAny = false;
	//上传设置
	/** 是否任何网络上传 */
	private boolean uploadAny = false;
	
	//用户体验设置
	/** 双击关闭视频 */
	private boolean doubleClickClose = true;
	/** 左右视频滑动 */
	private boolean horizontalFlip = true;
	
	//消息提醒
	/** 关注消息 */
	private boolean focusNotice;
	/** 评论消息 */
	private boolean commentNotice;
	/** 系统消息 */
	private boolean systemNotice;
	/** 消息提示音 */
	private boolean noticeAlarm;
	/** 震动 */
	private boolean noticeDisturb;
	/** 圈子私信 */
	private boolean circleSiXin;
	/** 圈子新贴 */
	private boolean circleXinTie;
	/** @我的*/
	private boolean circleTidaoMe;
	/** 关注新贴 */
	private boolean focousXinTie;
	/** 关注新贴 */
	private boolean mySiXin;
	
	/**个人中心中的本地提醒 */
	private boolean bendiNotice;
	
	public boolean isVideoDetailPageAutoPlay() {
		return videoDetailPageAutoPlay;
	}

	public void setVideoDetailPageAutoPlay(boolean videoDetailPageAutoPlay) {
		this.videoDetailPageAutoPlay = videoDetailPageAutoPlay;
	}

	public boolean isVideoAutoPlayAny() {
		return videoAutoPlayAny;
	}

	public void setVideoAutoPlayAny(boolean videoAutoPlayAny) {
		this.videoAutoPlayAny = videoAutoPlayAny;
	}

	public boolean isUploadAny() {
		return uploadAny;
	}

	public void setUploadAny(boolean uploadAny) {
		this.uploadAny = uploadAny;
	}

	public boolean isDoubleClickClose() {
		return doubleClickClose;
	}

	public void setDoubleClickClose(boolean doubleClickClose) {
		this.doubleClickClose = doubleClickClose;
	}

	public boolean isHorizontalFlip() {
		return horizontalFlip;
	}

	public void setHorizontalFlip(boolean horizontalFlip) {
		this.horizontalFlip = horizontalFlip;
	}

	public boolean isFocusNotice() {
		return focusNotice;
	}

	public void setFocusNotice(boolean focusNotice) {
		this.focusNotice = focusNotice;
	}

	public boolean isCommentNotice() {
		return commentNotice;
	}

	public void setCommentNotice(boolean commentNotice) {
		this.commentNotice = commentNotice;
	}

	public boolean isSystemNotice() {
		return systemNotice;
	}

	public void setSystemNotice(boolean systemNotice) {
		this.systemNotice = systemNotice;
	}

	public boolean isNoticeAlarm() {
		return noticeAlarm;
	}

	public void setNoticeAlarm(boolean noticeAlarm) {
		this.noticeAlarm = noticeAlarm;
	}

	

	public boolean isNoticeDisturb() {
        return noticeDisturb;
    }

    public void setNoticeDisturb(boolean noticeDisturb) {
        this.noticeDisturb = noticeDisturb;
    }

    public boolean isCircleSiXin() {
		return circleSiXin;
	}

	public void setCircleSiXin(boolean circleSiXin) {
		this.circleSiXin = circleSiXin;
	}

	public boolean isCircleXinTie() {
		return circleXinTie;
	}

	public boolean isCircleTidaoMe() {
		return circleTidaoMe;
	}

	public void setCircleTidaoMe(boolean circleTidaoMe) {
		this.circleTidaoMe = circleTidaoMe;
	}

	public void setCircleXinTie(boolean circleXinTie) {
		this.circleXinTie = circleXinTie;
	}
	
	
	public boolean isFocousXinTie() {
		return focousXinTie;
	}

	public void setFocousXinTie(boolean focousXinTie) {
		this.focousXinTie = focousXinTie;
	}

	public boolean isMySiXin() {
		return mySiXin;
	}

	public void setMySiXin(boolean mySiXin) {
		this.mySiXin = mySiXin;
	}

	/**
     * @return the bendiNotice
     */
    public boolean isBendiNotice() {
        return bendiNotice;
    }

    /**
     * @param bendiNotice the bendiNotice to set
     */
    public void setBendiNotice(boolean bendiNotice) {
        this.bendiNotice = bendiNotice;
    }

    public void saveData(Context context){
		
		SharedPreferences settings = context.getSharedPreferences("user" + LoginInfo.getInstance().getUserId(), 0);
		SharedPreferences.Editor spEditor = settings.edit();
		
		spEditor.putBoolean("videoDetailPageAutoPlay", videoDetailPageAutoPlay);
		spEditor.putBoolean("uploadAny", uploadAny);
		spEditor.putBoolean("doubleClickClose", doubleClickClose);
		spEditor.putBoolean("horizontalFlip", horizontalFlip);
		spEditor.putBoolean("focusNotice", focusNotice);
		spEditor.putBoolean("commentNotice", commentNotice);
		spEditor.putBoolean("systemNotice", systemNotice);
		spEditor.putBoolean("noticeAlarm", noticeAlarm);
		spEditor.putBoolean("noticeShake", noticeDisturb);
		spEditor.putBoolean("bendiNotice", bendiNotice);
		spEditor.putBoolean("circleSiXin", circleSiXin);
		spEditor.putBoolean("circleXinTie", circleXinTie);
		spEditor.putBoolean("circleTidaoMe", circleTidaoMe);
		spEditor.putBoolean("mySiXin", mySiXin);
		spEditor.putBoolean("focousXinTie", focousXinTie);
		spEditor.putBoolean("videoAutoPlayAny", videoAutoPlayAny);
		
		spEditor.commit();
		
	}
	
	private void loadData(Context context){
		SharedPreferences settings = context.getSharedPreferences("user" + LoginInfo.getInstance().getUserId(), 0);
		if(settings.contains("videoDetailPageAutoPlay")){
			setVideoDetailPageAutoPlay(settings.getBoolean("videoDetailPageAutoPlay", true));
			setUploadAny(settings.getBoolean("uploadAny", true));
			setDoubleClickClose(settings.getBoolean("doubleClickClose", true));
			setHorizontalFlip(settings.getBoolean("horizontalFlip", true));
			setFocusNotice(settings.getBoolean("focusNotice", true));
			setCommentNotice(settings.getBoolean("commentNotice", true));
			setSystemNotice(settings.getBoolean("systemNotice", true));
			setNoticeAlarm(settings.getBoolean("noticeAlarm", true));
			setNoticeDisturb(settings.getBoolean("noticeShake", true));
			setBendiNotice(settings.getBoolean("bendiNotice", true));
			setCircleSiXin(settings.getBoolean("circleSiXin", true));
			setCircleXinTie(settings.getBoolean("circleXinTie", true));
			setCircleTidaoMe(settings.getBoolean("circleTidaoMe", true));
			setMySiXin(settings.getBoolean("mySiXin", true));
			setFocousXinTie(settings.getBoolean("focousXinTie", true));
			setVideoAutoPlayAny(settings.getBoolean("videoAutoPlayAny", false));
		}else{
		    setVideoDetailPageAutoPlay(settings.getBoolean("videoDetailPageAutoPlay", true));
            setUploadAny(settings.getBoolean("uploadAny", true));
            setDoubleClickClose(settings.getBoolean("doubleClickClose", true));
            setHorizontalFlip(settings.getBoolean("horizontalFlip", true));
            setFocusNotice(settings.getBoolean("focusNotice", true));
            setCommentNotice(settings.getBoolean("commentNotice", true));
            setSystemNotice(settings.getBoolean("systemNotice", true));
            setNoticeAlarm(settings.getBoolean("noticeAlarm", true));
            setNoticeDisturb(settings.getBoolean("noticeShake", true));
            setBendiNotice(settings.getBoolean("bendiNotice", true));
            setCircleSiXin(settings.getBoolean("circleSiXin", true));
			setCircleXinTie(settings.getBoolean("circleXinTie", true));
			setCircleTidaoMe(settings.getBoolean("circleTidaoMe", true));
			setMySiXin(settings.getBoolean("mySiXin", true));
			setFocousXinTie(settings.getBoolean("focousXinTie", true));
			setVideoAutoPlayAny(settings.getBoolean("videoAutoPlayAny", false));
            saveData(context);
		}
		
	}
	
}
